﻿#判断是否是SpringBoot应用程序
#判断依据Pom文件中的spring-boot-starter-parent
#判断模式是否为检测模式
# $OutputEncoding = [System.Text.Encoding]::utf8
#命名规则 模版文件就用 T_(template)开头 F_表示文件 P_表示路径
# 项目文件命名规则 P_(Project) 开头 F_表示文件 P_表示路径
#举例 T_F_Test 就表示模版文件 Test TemplateFile-Test
$encoding = New-Object System.Text.UTF8Encoding($false)
$T_P_HOME=".temp\.template\MavenWeb\Original\"
$T_F_Test=".\.temp\.template\MavenWeb\Original\test_.java"
$T_P_Resources=".\.temp\src\main\resources"



$P_P_Resources=".\src\main\resources"
$P_P_Yyge=".\src\main\java\com\yyge\"
$P_P_Main=".\src\main\"

$P_P_Entity=".\src\main\java\com\yyge\entity"
$P_P_Mapper=".\src\main\java\com\yyge\mapper"
$P_P_XmlMapper=".\src\main\resources\mapper"
$P_P_Test=".\src\test\java\com\yyge\mapper\"

#缓存路径 CodeAutoGenerator 简称CodeAG
$C_P_CodeAG="C:\Users\Administrator\AppData\Local\CodeAG"
$C_P_Data="C:\Users\Administrator\AppData\Local\CodeAG\.Data"
$C_F_User="C:\Users\Administrator\AppData\Local\CodeAG\.Data\user.data"


#不存在则创建 以免Get-ChildItem报错 Test-Path
CreateDir($P_P_XmlMapper)
CreateDir($P_P_Test)#判断文件夹是否存在
CreateDir($C_P_CodeAG) #创建缓存目录用于存放Data
CreateDir($C_P_Data) #创建缓存目录用于存放Data
if((Get-ChildItem $P_P_XmlMapper -File).Count -eq 0){
    $P_P_XmlMapper=".\src\main\resources\com\yyge\mapper\"  
}

if($Detection -ne $true){
    CreateDir($P_P_Yyge)
    CreateDir($P_P_Main)
    CreateDir($P_P_Entity)#判断文件夹是否存在
    CreateDir($P_P_Mapper)#判断文件夹是否存在
}

if($Detection -eq $false){
    $OPT=Read-Host "==>是否注入相关Maven依赖? 是(1)/否(2)"
    if($OPT -eq 1){
            $SpringBoot=$true
            $SpringBootPomText=Get-Content -Encoding utf8 -Path $Pom -Raw
            #判断依据为报红问题是否引入
            if($SpringBootPomText.IndexOf("mysql-connector") -eq -1){
                if($SpringBootPomText.IndexOf("<parent>") -ne -1){
                    $SpringBootPomText=$SpringBootPomText -replace "<parent>","`n  <!--当前项目继承的依赖关系-->`n    <parent>"
                }
                if($SpringBootPomText.IndexOf("<groupId>com.yyge") -ne -1){
                    $SpringBootPomText=$SpringBootPomText -replace "<groupId>com.yyge","`n 	<!--项目的坐标以及打包方式-->`n    <groupId>com.yyge"
                }

                $PomTemplateText=Get-Content -Encoding utf8 -Path ($ProjectHome+".temp\.template\MavenWeb\Original\pom_.xml") -Raw
                
                $ReplaceTxt=[Regex]::Split($SpringBootPomText, "</dependencies>")
                $TempText=""
                for ($i = 0; $i -lt $ReplaceTxt.Length; $i++) {
                  #判断是否为最后一个元素
                  if($i -ne ($ReplaceTxt.Length-1)){
                    if($ReplaceTxt[$i].IndexOf("<dependencyManagement>") -eq -1){
                        $TempText=($TempText+$ReplaceTxt[$i]+"</dependencies>") -replace "</dependencies>",($PomTemplateText+"`n")
                       }else{
                        $TempText=($TempText+$ReplaceTxt[$i]+"</dependencies>")
                       }
                  }else{
                    $TempText=($TempText+$ReplaceTxt[$i])
                  }
                }
                [System.IO.File]::WriteAllLines($Pom,$TempText,$encoding)
            }


    }
}

# 需求:复制一个文件夹里的所有文件夹到对应的目录 只要项目内不存在就复制 #
<# 复制一个文件夹里面所有的目录到另一个文件夹里面 + 判断  最多判断两级目录 #>
function CopyFile($CopyDir,$TargetDir) {
  $DriectryList = Get-ChildItem -Path $CopyDir -Recurse -Directory -Depth 0
  foreach ($Directory in $DriectryList) {
      if(Test-Path -Path ($TargetDir+"\"+$Directory.Name)){
        <# 有当前文件夹再次遍历文件夹里的文件 #>
        $FileList = Get-ChildItem -Path $Directory.FullName -Recurse -File -Depth 0
        $DirList = Get-ChildItem -Path $Directory.FullName -Recurse -Directory -Depth 0

        # Read-Host ("文件夹 "+ $Directory.Name +" DirList的个数："+$DirList.Length)

        foreach ($File in $FileList) {
          $FilePath=$TargetDir+"\"+$Directory.Name+"\"+$File
          if(!(Test-Path -Path $FilePath)){
            <# 如果没有当前文件的话则复制过去 #>
            Copy-Item -Path $File.FullName -Destination ($TargetDir+"\"+$Directory.Name) -Recurse -Force | Out-Null
          }
        }
        <# 如果文件里面还有文件夹则递归调用 #>
        if($DirList.Length -ne 0){
          CopyFile $Directory.FullName ($TargetDir+"\"+$Directory.Name)
        }
      }else{
       <# 没有当前文件夹则复制 #>
       Copy-Item -Path $Directory.FullName -Destination $TargetDir -Recurse -Force | Out-Null
      }  
  }
}


if($Detection -ne $true){
 CopyFile $T_P_HOME $P_P_Yyge
}


if(($SpringBoot -ne $true) -and ($Detection -ne $true)){
    #复制resources资源目录
    Copy-Item -Path $T_P_Resources -Destination $P_P_Main -Recurse -Force | Out-Null
}


$TestFileBody=Get-Content -Encoding utf8 $T_F_Test -Raw
# $ControllerFileBody=Get-Content -Encoding utf8 $T_F_Controller -Raw

$Y_EntityName="temp"
$Data=@{}
#实例类名 list
$Y_EntityNameList = @()

#数据库列明
$BDColumnNameList = @()

#实体类属性
$EntityNameList = @()

#数据库列的类型
$jdbcTypeList = @()

#数据库表名
$DBTableNameList = @()

# 备注
$NoteList=@()
$Noteverify=@()


#删除EmployeeMapper.xml 如果存在的话
if(Test-Path -Path ".\src\main\resources\com\yyge\mapper\EmployeeMapper.xml"){
    if($Detection -ne $true){
     Remove-Item -Path ".\src\main\resources\com\yyge\mapper\EmployeeMapper.xml" -Force | Out-Null
    }
}

Get-ChildItem -Path $P_P_Mapper -Recurse | ForEach-Object {
    if (!$_.PSIsContainer) {
        #列备注 
        # 如果是文件而不是文件夹，则调用提供的函数对文件内容进行替换操作
        #(Get-Content $_.FullName) | Set-Content -Encoding $encoding $_.FullName
        if($_.Name.Contains("Mapper.java")){
            $Name=($_.Name -replace  "Mapper.java","")
            if($Name -ne "Base"){
                $autoInt=-1
                #判断不为检测模式
                if($Detection -ne $true){
                    $autoInt=Read-Host ("是否自动创建 "+$Name+" 实体类相关后端文件?"+" 是(1)/否(2)")
                    Write-Host ("`n-->>"+$Name+" 实体类正在创建...") -ForegroundColor Green  
                 }else{
                    Write-Host ("`n-->>"+$Name+" 实体类扫描开始") -ForegroundColor Green   
                }

                if(($autoInt -eq 1) -or ($Detection -eq $true)){
                    #替换Entity文件内容--改造entity
                    
                    $P_F_Entity=$P_P_Entity+"\"+($Name)+".java"
                    $EntityFileBody=Get-Content -Encoding utf8 $P_F_Entity -Raw


                    #给entity添加上集合 并且导入集合类 import java.util.Map;
                    $EntityFileBody2=Get-Content -Encoding utf8 $P_F_Entity -Raw
                    if($EntityFileBody2.IndexOf("private Map<String, Object> params;") -eq -1){
                    $EntityFileBody=$EntityFileBody2 -replace "private static final long serialVersionUID = 1L;","private Map<String, Object> params;`n    private static final long serialVersionUID = 1L;`n"
                    $EntityFileBody=$EntityFileBody -replace "import java.io.Serializable;","import java.io.Serializable;`nimport java.util.Map;"
                    if($Detection -ne $true){
                      [System.IO.File]::WriteAllLines($P_F_Entity, $EntityFileBody,$encoding)
                    }
                    }

                    $P_F_Mapper_T=Get-Content -Encoding utf8 -Path $_.FullName -Raw

                    #给Mapper文件添加上@Mapper的注解
                    if(($Detection -ne $true) -and ($P_F_Mapper_T.IndexOf("@Mapper") -eq -1)){
                        $P_F_Mapper_T=$P_F_Mapper_T -replace "public interface","@Mapper`npublic interface"
                        $P_F_Mapper_T=$P_F_Mapper_T -replace "import com.baomidou.mybatisplus.core.mapper.BaseMapper;","import com.baomidou.mybatisplus.core.mapper.BaseMapper;`nimport org.apache.ibatis.annotations.Mapper;"
                        [System.IO.File]::WriteAllLines($_.FullName, $P_F_Mapper_T,$encoding)
                      }

                    $Y_EntityName=$Name
                    $Y_EntityNameList += $Name

                    #提取含有备注的列
                    $P_F_Entity=$P_P_Entity+"\"+($Name)+".java"
                    #临时数组用于存储 列的备注以及验证信息-- 
                    $Note_TempList = setColumInfo $P_F_Entity
                    $NoteList+=,$Note_TempList[0]
                    $Noteverify+=,$Note_TempList[1]
                    $DBTableNameList+=$Note_TempList[2]


                    #创建测试-全查selectAll
                    $Temp9=$TestFileBody -replace "_____",$Name
                    $Temp10=$P_P_Test+"\"+($Name)+"MapperTest.java"
                    if($Detection -ne $true){
                     New-Item -ItemType File -Path $Temp10 -Value $Temp9 -Force | Out-Null
                     Write-Host ("-->>"+$Name+" 实体类相关后端文件已成功创建`n") -ForegroundColor Green
                    }else{
                        Write-Host ("-->>"+$Name+" 实体类已扫描完毕`n") -ForegroundColor Green   
                    }
                }
            }
        }
    }
}



Get-ChildItem -Path $P_P_XmlMapper -Recurse | ForEach-Object {
    if (!$_.PSIsContainer) {
        $DBTableName=""
        # 如果是文件而不是文件夹，则调用提供的函数对文件内容进行替换操作
        #(Get-Content $_.FullName) | Set-Content -Encoding $encoding $_.FullName
        if($_.Name.Contains("Mapper.xml") -and ($_.Name -ne "BaseMapper.java")){
            $bodyTxt =Get-Content $_.FullName -Encoding utf8 -Raw
            $words = [Regex]::Split($bodyTxt,"`r`n+")
            
            #数据库 列名
            $BDColumnName = @()
            #实体类属性
            $EntityName = @()
            #数据库列的类型
            $jdbcType = @()

            $Temp_sub=0
            foreach ($word in $words) {
                if($word.IndexOf("BaseResultMap") -ne -1){$Temp_sub=1 }
 
                if($Temp_sub -eq 1 -and $word.IndexOf("jdbcType=`"") -gt -1){
                    $ReplaceTxt=[Regex]::Split($word, "`"")
                    $BD_N_N = $ReplaceTxt[3].Trim()
                    $EN_N_N=$ReplaceTxt[1].Trim()

                    $EntityName += $EN_N_N
                    $BDColumnName += $BD_N_N
                    
                    $TY_N_N=$ReplaceTxt[5].Trim()
                    $jdbcType += $TY_N_N
                }
            }

            # #如下代码嵌套为二维数组
            # $DBTableNameList += $DBTableName
            $BDColumnNameList += ,$BDColumnName
            #实体类属性
            $EntityNameList += ,$EntityName
            #数据库列的类型
            $jdbcTypeList += ,$jdbcType

        }
    }
}

#删除EmployeeMapper.xml
if(Test-Path -path ".\src\main\java\com\yyge\web\servlet\IndexServlet.java"){
    if($Detection -ne $true){
      Remove-Item -Path ".\src\main\java\com\yyge\web\servlet\IndexServlet.java"
    }
}



Write-Host "准备打印基础data...."
$Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')
Write-Host "EntityNameList:"
Write-Host $EntityNameList

Write-Host "BDColumnNameList:"
Write-Host $BDColumnNameList

Write-Host "jdbcTypeList:"
Write-Host $jdbcTypeList


$Noteverify_T=@()
$NoteList_T=@()
for ($i = 0; $i -lt $EntityNameList.Length; $i++) {
    $V=@()
    $L=@()
  for ($j = 0; $j -lt $EntityNameList[$i].Length; $j++) {
    if($EntityNameList[$i][$j] -eq $Noteverify[$i][$j]){
        $V+=$Noteverify[$i][$j]
        $L+=$NoteList[$i][$j]
    }
  }
  $Noteverify_T+=,$V
  $NoteList_T+=,$L
}
$Noteverify=$Noteverify_T
$NoteList=$NoteList_T

# Data转Json 只有基础的Data内容
$Data.Add("Y_EntityNameList", $Y_EntityNameList)
$Data.Add("BDColumnNameList", $BDColumnNameList)
$Data.Add("EntityNameList", $EntityNameList)
$Data.Add("jdbcTypeList", $jdbcTypeList)
$Data.Add("DBTableNameList", $DBTableNameList)
$Data.Add("NoteList", $NoteList)
$Data.Add("Noteverify", $Noteverify)

$DataJson=$Data | ConvertTo-Json -Compress

#声明二维数组用于存放登录的信息 实体类的类名 账号属性名、密码属性名
$LoginEntityName,$LogInEntiCount,$LogInEntiPass=@(),@(),@()

# 创建配置文件
$DataFile="./.temp/.data/config.data"
New-Item -ItemType File -Path $DataFile -Force | Out-Null
[System.IO.File]::WriteAllLines($DataFile,$DataJson,$encoding)

#写入缓存User Cach
$UserCachePath=$C_P_CodeAG+"\.Data\config.data"
New-Item -ItemType File -Path $UserCachePath -Force | Out-Null
[System.IO.File]::WriteAllLines($UserCachePath,$DataJson,$encoding)


#在项目目录中创建一个名为.data的目录
$ProjectDataPath="./.data/"
CreateDir($ProjectDataPath)
#在项目目录中创建一个config.data的文件记录所有data数据
$ProjectDataFile="./.data/config.data"
New-Item -ItemType File -Path $ProjectDataFile -Force | Out-Null
[System.IO.File]::WriteAllLines($ProjectDataFile,$DataJson,$encoding)


#controller主键替换
for ($i = 0; $i -lt $Y_EntityNameList.Length; $i++) {
    $P_F_Controller=$P_P_Controller+"\"+$Y_EntityNameList[$i]+"Controller.java"
    $Str_4="get"+($EntityNameList[$i][0].Substring(0,1).ToUpper()+$EntityNameList[$i][0].Substring(1))
    $ControllerBody=(Get-Content -Encoding utf8 -Path $P_F_Controller -Raw) -replace "getId",$Str_4
    [System.IO.File]::WriteAllLines($P_F_Controller,$ControllerBody,$encoding)
}


#登陆检测
for ($i = 0; $i -lt $Y_EntityNameList.Length; $i++) {
    #将数组转换为字符串 判断内容是否包含xxx,xxx
    $BDCountCol="" # DB账号列名
    $BDPassCol="" # DB密码列名
    $BDIDCol="" # DBID列名
    $BDNameCol="" # DB昵称列名
    $BDAvatarCol="" # DB头像地址列名
    $BDStatusCol="" # DB状态列名
    $BDTypeCol="" # DB类型列名


    $EnCountAtt="" # 实体类账号属性名
    $EnPassAtt="" # 实体类密码属性名
    $EnIDAtt="" # 实体类ID属性名
    $EnNameAtt="" # 实体类昵称属性名
    $EnAvatarAtt="" # 实体类头像地址属性名
    $EnStatusAtt="" # 实体类状态属性名
    $EnTypeAtt="" # 实体类类型属性名

    #声明二维数组用于存放登录的信息 实体类的类名 账号属性名、密码属性名
    #_T 临时存放 在循环后加入主文件 由此得到二维数组,LoginEntityName存放的是实体类的类名所以他不存在二维数组直接存放即可
    $LoginEntityName_T,$LogInEntiCount_T,$LogInEntiPass_T=@(),@(),@()
    $LoginEntityID_T,$LogInEntiNickName_T,$LogInEntiAvatar_T=@(),@(),@()
    $LoginEntityStatus_T,$LogInEntiType_T=@(),@()
    $NoteStr = $NoteList[$i] -join ","
    $LoginPass = -1 
    # 判断依据就是有账号&密码
    if(($NoteStr.IndexOf("账号") -ne -1) -or ($NoteStr.IndexOf("账户") -ne -1)){
     if($NoteStr.IndexOf("密码") -ne -1){
       $LoginPass=1
     }
    }
    if($LoginPass -eq 1){
      # 用户ID
      # 昵称
      # 登陆账户
      # 登陆密码
      # 头像地址
      # 用户状态
      # 用户类型
        for ($j = 0; $j -lt $NoteList[$i].Length; $j++) {
            $V=$NoteList[$i][$j]
            if(($V -eq "账号") -or ($V -eq "账户")){
                $EnCountAtt=$EntityNameList[$i][$j]
                $BDCountCol=$BDColumnNameList[$i][$j]
            }
            if($V -eq "密码"){
                $EnPassAtt=$EntityNameList[$i][$j]
                $BDPassCol=$BDColumnNameList[$i][$j]
            }
            if($V -eq "ID"){
                $EnIDAtt=$EntityNameList[$i][$j]
                $BDIDCol=$BDColumnNameList[$i][$j]
            }

            if($V -eq "昵称"){
                $EnNameAtt=$EntityNameList[$i][$j]
                $BDNameCol=$BDColumnNameList[$i][$j]
            }

            if($V.IndexOf("头像") -ne -1){
                $EnAvatarAtt=$EntityNameList[$i][$j]
                $BDAvatarCol=$BDColumnNameList[$i][$j]
            }
            if($V.IndexOf("状态") -ne -1){
                $EnStatusAtt=$EntityNameList[$i][$j]
                $BDStatusCol=$BDColumnNameList[$i][$j]
            }
            if($V.IndexOf("类型") -ne -1){
                $EnTypeAtt=$EntityNameList[$i][$j]
                $BDTypeCol=$BDColumnNameList[$i][$j]
            }
        }
    }

    if($BDCountCol -ne ""){
        $Str_1="  检测到 "+ $Y_EntityNameList[$i]+" 实体类似乎需要登陆功能..."
        $Str_2="  ----> 账号属性: "+$EnCountAtt
        $Str_3="  ----> 密码属性: "+$EnPassAtt
        $Str_4="  ----> ID属性: "+$EnIDAtt
        $Str_5="  ----> 昵称属性: "+$EnNameAtt
        $Str_6="  ----> 头像属性: "+$EnAvatarAtt
        $Str_7="  ----> 状态属性: "+$EnStatusAtt
        $Str_8="  ----> 类型属性: "+$EnTypeAtt
        Write-Host ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" -ForegroundColor Blue 
        Write-Host $Str_1 -ForegroundColor Blue 
        Write-Host $Str_2 -ForegroundColor Blue 
        Write-Host $Str_3 -ForegroundColor Blue 
        Write-Host $Str_4 -ForegroundColor Blue 
        Write-Host $Str_5 -ForegroundColor Blue 
        Write-Host $Str_6 -ForegroundColor Blue 
        Write-Host $Str_7 -ForegroundColor Blue 
        Write-Host $Str_8 -ForegroundColor Blue 
        Write-Host ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" -ForegroundColor Blue 
        $InputNum=Read-Host "  是否需要加入登陆功能？是(1)/否(2)"
        if($InputNum -eq 1){
        #   $LogTextPath=$P_P_XmlMapper+$Y_EntityNameList[$i]+"Mapper.xml"
        #   $Text1="<select id=`"login`" resultMap=`"BaseResultMap`">`n"
        #   $Text1=$Text1+"        select`n"+"             <include refid=`"Base_Column_List`" />`n"+"       from "+$DBTableNameList[$i]+"`n           where "+$BDCountCol+" = #{"+$EnCountAtt+"} and "+$BDPassCol+" = #{"+$EnPassAtt+"}`n"+"    </select>`n"
        #   $XmlTextBody=(Get-Content -Encoding utf8  $LogTextPath -Raw) -replace ("<select id=`"login`" resultMap=`"BaseResultMap`"/>"),$Text1
        #   [System.IO.File]::WriteAllLines($LogTextPath,$XmlTextBody,$encoding)
          
          #将Test.java中的@Login进行替换
          $TestPath=$P_P_Test+"\"+$Y_EntityNameList[$i]+"MapperTest.java"
          $ToUpperCount=($EnCountAtt.Substring(0,1).ToUpper()+$EnCountAtt.Substring(1))
          $ToUpperPass=($EnPassAtt.Substring(0,1).ToUpper()+$EnPassAtt.Substring(1))
          $Text2="@Test`n    public void login(){`n        _____Service service=new _____ServiceImpl();`n        _____ user=new _____();`n"
          $Text2=$Text2+"        user.set"+$ToUpperCount+"(`"xxxxxxxxxx`");`n        user.set"+$ToUpperPass+"(`"xxxxxxxxxx`");`n        //设置对象的账号和密码`n        R r =service.login(user);`n        System.out.println(r.getData());`n    }"
          $Text2=$Text2 -replace "_____",$Y_EntityNameList[$i]
          $TestBody=(Get-Content -Encoding utf8  $TestPath -Raw) -replace "@Login",$Text2

          [System.IO.File]::WriteAllLines($TestPath,$TestBody,$encoding)

          #将关键数据传入临时的数组 登录实体类的账号、密码属性 
          $LogInEntiCount_T+=$EnCountAtt
          $LogInEntiPass_T+=$EnPassAtt
          $LogInEntiID_T+=$EnIDAtt
          $LogInEntiNickName_T+=$EnNameAtt
          $LogInEntiAvatar_T+=$EnAvatarAtt
          $LogInEntiStatus_T+=$EnStatusAtt
          $LogInEntiType_T+=$EnTypeAtt
          $LoginEntityName_T+=$Y_EntityNameList[$i]
        }else{
            #如果用户选择了"否" 则会直接将Test.java中的@Login删除
            $TestPath=$P_P_Test+"\"+$Y_EntityNameList[$i]+"MapperTest.java"  
            $TestBody=(Get-Content -Encoding utf8  $TestPath -Raw) -replace "@Login",""
            [System.IO.File]::WriteAllLines($TestPath,$TestBody,$encoding)
        }
    }else{
        #如果当前实体类没有登陆项 则会直接将Test.java中的@Login删除
        $TestPath=$P_P_Test+"\"+$Y_EntityNameList[$i]+"MapperTest.java"  
        $TestBody=(Get-Content -Encoding utf8  $TestPath -Raw) -replace "@Login",""
        [System.IO.File]::WriteAllLines($TestPath,$TestBody,$encoding)
    }

    if($LogInEntiCount_T.Length -gt 0){
      $UserData=@{}
      $UserDataBody=""
      $UserDataObject=@{}

      #取读user文件的内容
      if(Test-Path -path ".\.data\user.data"){
        $UserDataBody=Get-Content -Path ".\.data\user.data" -Encoding utf8 -Raw
      }

      
      Write-Host ("正在准备判断 UserDataBody:"+($UserDataBody.Length))
      $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')
      if(($UserDataBody.Length) -ne 0){
        Write-Host ("我来了")
        $ObjectUser=@{}
        $UserDataObject=ConvertFrom-Json $UserDataBody
        Write-Host $UserDataObject
        $Arr_1=@()
        $Arr_1+=$UserDataObject["entityName"]
        $Arr_1+=$Y_EntityNameList[$i]
        $ObjectUser.Add("entityName",$Arr_1)

        $Arr_2=@()
        $Arr_2+=,$UserDataObject["LogInEntiCount"]
        $Arr_2+=,$LogInEntiCount_T
        $ObjectUser.Add("LogInEntiCount",$Arr_2)

        $Arr_3=@()
        $Arr_3+=,$UserDataObject["LogInEntiPass"]
        $Arr_3+=,$LogInEntiPass_T
        $ObjectUser.Add("LogInEntiPass",$Arr_3)

        $Arr_4=@()
        $Arr_4+=,$UserDataObject["LogInEntiId"]
        $Arr_4+=,$LogInEntiId_T
        $ObjectUser.Add("LogInEntiId",$Arr_4)

        $Arr_5=@()
        $Arr_5+=,$UserDataObject["LogInEntiName"]
        $Arr_5+=,$LogInEntiNickName_T
        $ObjectUser.Add("LogInEntiName",$Arr_5)
        
        $Arr_6=@()
        $Arr_6+=,$UserDataObject["LogInEntiAvatar"]
        $Arr_6+=,$LogInEntiAvatar_T
        $ObjectUser.Add("LogInEntiAvatar",$Arr_6)

        $Arr_7=@()
        $Arr_7+=,$UserDataObject["LogInEntiStatus"]
        $Arr_7+=,$LogInEntiStatus_T
        $ObjectUser.Add("LogInEntiStatus",$Arr_7)

        $Arr_8=@()
        $Arr_8+=,$UserDataObject["LogInEntiType"]
        $Arr_8+=,$LogInEntiType_T
        $ObjectUser.Add("LogInEntiType",$Arr_8)

      }else{
        $ObjectUser=@{}
        $ObjectUser.Add("entityName",$Y_EntityNameList[$i])

        $ObjectUser.Add("LogInEntiCount",$LogInEntiCount_T)
        $ObjectUser.Add("LogInEntiPass",$LogInEntiPass_T)
        $ObjectUser.Add("LogInEntiID",$LogInEntiID_T)
        $ObjectUser.Add("LogInEntiName",$LogInEntiName_T)
        $ObjectUser.Add("LogInEntiAvatar",$LogInEntiAvatar_T)
        $ObjectUser.Add("LogInEntiStatus",$LogInEntiStatus_T)
        $ObjectUser.Add("LogInEntiType",$LogInEntiType_T)

        Write-Host ("查看临时LogInEntiCount=="+$LogInEntiCount_T)
        Write-Host ("查看临时LogInEntiPass=="+$LogInEntiPass_T)
        $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')
        
      }

      $DataJson=$ObjectUser | ConvertTo-Json -Compress

       #临时存储登陆功能对应的entity名Get-Content
       New-Item -ItemType File -Path ".\.Data\user.data" -Force | Out-Null
       [System.IO.File]::WriteAllLines(".\.Data\user.data",$DataJson,$encoding)

       $C_F_User=$C_P_CodeAG+"\.data\user.data"
       New-Item -ItemType File -Path $C_F_User -Force | Out-Null
       [System.IO.File]::WriteAllLines($C_F_User,$DataJson,$encoding)

       # Set-Content -Encoding $encoding -Path ".\.data\user.data" -Force -Value  $DataJson | Out-Null
    }
}

# 首字母转大写
function StrOneToUpper($Str) {
  return ($Str.Substring(0,1).ToUpper() + $Str.Substring(1))
}

# 首字母转小写
function StrOneToLower($Str) {
  return ($Str.Substring(0,1).ToLower() + $Str.Substring(1))
}

if(Test-Path -Path $C_F_User){
  $C_F_UserText=Get-Content -Encoding utf8 -Path $C_F_User -Raw

  $UserData=ConvertFrom-Json $C_F_UserText
  $P_F_LoginController=".\src\main\java\com\yyge\controller\LoginController.java"
  $LoginCtrollerText=Get-Content -Path  $P_F_LoginController -Encoding utf8 -Raw

  # 赋值Data数据
  $User_EntityName=$UserData.entityName
  $User_LogInEntiCount=$UserData.LogInEntiCount[1]
  $User_LogInEntiPass=$UserData.LogInEntiPass[1]
  $User_LogInEntiId=$UserData.LogInEntiId[1]
  $User_LogInEntiName=$UserData.LogInEntiName[1]
  $User_LogInEntiAvatar=$UserData.LogInEntiAvatar[1]
  $User_LogInEntiType=$UserData.LogInEntiType[1]

  Read-Host ("User_EntityName:$User_EntityName")
  Read-Host ("User_LogInEntiCount:$User_LogInEntiCount")
  Read-Host ("User_LogInEntiPass:$User_LogInEntiPass")
  Read-Host ("User_LogInEntiId:$User_LogInEntiId")
  Read-Host ("User_LogInEntiName:$User_LogInEntiName")
  Read-Host ("User_LogInEntiAvatar:$User_LogInEntiAvatar")
  Read-Host ("User_LogInEntiType:$User_LogInEntiType")
  
  $LoginCtrollerText = $LoginCtrollerText -replace "_____",(StrOneToUpper $User_EntityName)
  $LoginCtrollerText = $LoginCtrollerText -replace "__.MinName.__",(StrOneToLower $User_EntityName)
  $LoginCtrollerText = $LoginCtrollerText -replace "__.PwdName.__",(StrOneToUpper $User_LogInEntiPass)
  $LoginCtrollerText = $LoginCtrollerText -replace "__.LoginName.__",(StrOneToUpper $User_LogInEntiCount)

  $LoginUserStr="LoginUserVo loginUser = new LoginUserVo();`n"
  if($User_LogInEntiId.Trim() -ne ""){
    $LoginUserStr=$LoginUserStr+"       loginUser.setId(Integer.parseInt("+(StrOneToLower $User_EntityName)+".get"+(StrOneToUpper $User_LogInEntiId)+"()+`"`"));`n"
  }

  if($User_LogInEntiName.Trim() -ne ""){
    $LoginUserStr=$LoginUserStr+"       loginUser.setName("+(StrOneToLower $User_EntityName)+".get"+(StrOneToUpper $User_LogInEntiName)+"());`n"
  }

  if($User_LogInEntiCount.Trim() -ne ""){
    $LoginUserStr=$LoginUserStr+"       loginUser.setLoginName("+(StrOneToLower $User_EntityName)+".get"+(StrOneToUpper $User_LogInEntiCount)+"());`n"
  }

  if($User_LogInEntiPass.Trim() -ne ""){
    $LoginUserStr=$LoginUserStr+"       loginUser.setLoginPwd("+(StrOneToLower $User_EntityName)+".get"+(StrOneToUpper $User_LogInEntiPass)+"());`n"
  }
  
  if($User_LogInEntiAvatar.Trim() -ne ""){
    $LoginUserStr=$LoginUserStr+"       loginUser.setAvatar("+(StrOneToLower $User_EntityName)+".get"+(StrOneToUpper $User_LogInEntiAvatar)+"());`n"
  }

  if($User_LogInEntiType.Trim() -ne ""){
    $LoginUserStr=$LoginUserStr+"       loginUser.setAccountType("+(StrOneToLower $User_EntityName)+".get"+(StrOneToUpper $User_LogInEntiType)+"());`n"
  }
  



  $LoginCtrollerText = $LoginCtrollerText -replace "<---LoginUser--->",$LoginUserStr
  [System.IO.File]::WriteAllLines($P_F_LoginController,$LoginCtrollerText,$encoding)

}

$Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')

# 调用后端脚本文件
# if($Detection -ne $true){
#     & "./.temp/.script/backend.ps1"
#    }
#    $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')
   #调用前端文件
  #  if($Detection -ne $true){
  #   & "./.temp/.script/foreend.ps1"
  #  }
  #  $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')

